// JavaScript Document
var allData = null
$(document).ready(function() {
	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2]);
		}
		return null;
	}
	$.get("./info.json",
		function(data, status) {
			let weight = 0
			allData = data[getUrlParam("n")?Number(getUrlParam("n"))-1:1],
				eleAllURl = "&";
			for (var i = 0; i < allData.electrons.length; i++) {
				eleAllURl += `c${i+1}=${i+1}&num${i+1}=${allData.electrons[i]}`
				if (i != allData.electrons.length - 1) {
					eleAllURl += "&"
				}
			}
			$("#body").html(`<header>
			<img src="img/2017.png" class="heagerImg" onclick="window.location.href='index.html'">
			</header>
<center style="margin-top:20px;">
	<div class='big1'>
		<span id='zqt' class='b'>
		</span>
		<table id="eltable" rules='all' frame='box' bordercolor='#999999' cellpadding='1' cellspacing='1'
		style='font-size:92%; text-align: left' class='bigg2 yuanj' name='big4'>
			<tbody class='yuanj'>
				<tr class='b'>
					<td colspan='3' class='biaot'>
						基本概况
					</td>
				</tr>
				<tr>
					<td class='a'>
						元素名称
					</td>
					<td colspan='2'>${allData.CnName}(${allData.EnName}/${allData.LnName})
					</td>
				</tr>
				<tr>
					<td class='a'>
						元素符号
					</td>
					<td>
						${allData.symbol}
					</td>
					<td rowspan='3' style='width:80px;height:80px'>
						<img src='Pic/${allData.symbol}1.png' style='width:100px;height:100px'>
					</td>
				</tr>
				<tr>
					<td class='a'>
						原子序数
					</td>
					<td>
						${allData.atomic}
					</td>
					
				</tr>
				<tr>
					<td class='a'>
						标准原子质量
					</td>
					<td>
						${allData.weight}u
					</td>
					
				</tr>
				<tr>
					<td class='a'>
						电子排布
					</td>
					<td colspan='2'>
						${allData.electronstring}
					</td>
				</tr>
				
				
				
				<tr class='b'>
					<td colspan='3' class='biaot'>
						物理性质
					</td>
				</tr>
				<tr>
					<td class='a'>
						熔点
					</td>
					<td colspan='2'>
						${allData.melt?allData.melt+"K":"无"}
					</td>
				</tr>
				<tr>
					<td class='a'>
						沸点
					</td>
					<td colspan='2'>
						${allData.boil}K
					</td>
				</tr>
				<tr>
					<td class='a' rowspan="3">
						热能
					</td>
					<td colspan='2'>
						聚变热：${allData.heat&&allData.heat.boil?allData.heat.boil+"J/kgK":"无"}
					</td>
				</tr>
				<tr>
							
					<td colspan='2'>
						汽化热：${allData.heat&&allData.heat.vaporization}J/kgK
					</td>
				</tr>
				<tr>
				
					<td colspan='2'>
						融化热：${allData.heat&&allData.heat.fusion}J/kgK
					</td>
				</tr>
				
				<tr>
					<td class='a' rowspan="2">
						密度
					</td>
					<td colspan='2'>
						标况下：${allData.density&&allData.density.stp?allData.density.stp+"kg/m³":"无"}kg/m³
					</td>
				</tr>
				<tr>
				
					<td colspan='2'>
						<span id='sanx' class='b'>
						液态下：${allData.density&&allData.density.liquid?allData.density.liquid+"kg/m³":"无"}
						</span>
					</td>
				</tr>
				<tr>
					<td class='a'>
						导热系数
					</td>
					<td colspan='2'>
						${allData.conductivity&&allData.conductivity.thermal?allData.conductivity.thermal:"无"}
					</td>
				</tr>
				<tr>
					<td class='a'>
						导电系数
					</td>
					<td colspan='2'>
						${allData.conductivity&&allData.conductivity.electric?allData.conductivity.electric:"无"}
					</td>
				</tr>
				<tr Style="display:${allData.hardness?"":"none"}">
					<td class='a' rowspan="3">
						硬度
					</td>
					<td colspan='2'>
						维氏硬度：${allData.hardness&&allData.hardness.vickers?allData.hardness.vickers+"MPa":"无"}
					</td>
				</tr>
				<tr Style="display:${allData.hardness?"":"none"}">
							
					<td colspan='2'>
						布氏硬度：${allData.hardness&&allData.hardness.brinell?allData.hardness.brinell+"MPa":"无"}
					</td>
				</tr>
				<tr Style="display:${allData.hardness?"":"none"}">
				
					<td colspan='2'>
						莫氏硬度：${allData.hardness&&allData.hardness.mohs?allData.hardness.mohs+"MPa":"无"}
					</td>
				</tr>
				
				
				<tr Style="display:${allData.modulus?"":"none"}">
					<td class='a' rowspan="3">
						模量
					</td>
					<td colspan='2'>
						体积：${allData.modulus&&allData.modulus.bulk?allData.modulus.bulk+"GPa":"无"}
					</td>
				</tr>
				<tr Style="display:${allData.modulus?"":"none"}">
							
					<td colspan='2'>
						剪切：${allData.modulus&&allData.modulus.shear?allData.modulus.shear+"GPa":"无"}
					</td>
				</tr>
				<tr Style="display:${allData.modulus?"":"none"}">
				
					<td colspan='2'>
						杨氏：${allData.modulus&&allData.modulus.young?allData.modulus.young+"GPa":"无"}
					</td>
				</tr>
				
				<tr>
					<td class='a'>
						发现年份
					</td>
					<td colspan='2'>
						
						${allData.discover}
					
					</td>
				</tr>
				
				
				
							<tr class='b'>
								<td colspan='3' class='biaot'>
									原子性质
								</td>
							</tr>
							<tr>
								<td colspan='3'>
									<iframe src="noTool.html?aNum=${allData.electrons.length}${eleAllURl}" style="width:100%;border:0px;height:620px"></iframe>
								</td>
							</tr>
							<tr>
								<td class='a' rowspan="4">
									半径
								</td>
								<td colspan='2'>
									计算：${allData.radius&&allData.radius.calculated?allData.radius.calculated+"pm":"无"}
								</td>
							</tr>
							<tr>
										
								<td colspan='2'>
									试验：${allData.radius&&allData.radius.empirical?allData.radius.empirical+"pm":"无"}
								</td>
							</tr>
							<tr>
							
								<td colspan='2'>
									共价：${allData.radius&&allData.radius.covalent?allData.radius.covalent+"pm":"无"}pm
								</td>
							</tr>
							<tr>
							
								<td colspan='2'>
									范德华：${allData.radius&&allData.radius.vanderwaals?allData.radius.vanderwaals+"pm":"无"}pm
								</td>
							</tr>
							
							<tr>
								<td class='a'>
								第一电离能
								</td>
								<td colspan='2'>
									${allData.ionize["1"]}KJ
								</td>
							</tr>
							<tr>
								<td class='a'>
									原子谱线
								</td>
								<td colspan='2'>
									<img src='Pic2/${allData.symbol}2.png'>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
</center>`);



			$("#top").click(function() {
				$('#xl').slideToggle();
			});


			function getUrlParam(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return unescape(r[2]);
				}
				return null;
			}


			$("#last").html(`基本概况<br>元素名称： ${allData.CnName} <br>元素符号： ${allData.symbol} <br>原子序数： ${allData.atomic} <br>标准原子质量： ${allData.weight} <br>电子排布： ${allData.electronstring}
		"<br>-----------------<br>复制于彩叶化学，转载请保留出处`);

			function dynamicLoadCss(url) {
				var head = document.getElementsByTagName("head")[0];
				var link = document.createElement("link");
				link.type = "text/css";
				link.rel = "stylesheet";
				link.href = url;
				head.appendChild(link);
			}
			let type = allData.series
			if (type === "Alkali") {
				dynamicLoadCss("css/JJS.css")
			}
			if (type === "Nonmetal") {
				dynamicLoadCss("css/FJK.css")
			}
			if (type === "Alkaline") {
				dynamicLoadCss("css/JTJ.css")
			}
			if (type === "Transition") {
				dynamicLoadCss("css/GDU.css")
			}
			if (type === "Lanthanoid") {
				dynamicLoadCss("css/LXI.css")
			}
			if (type === "Actinoid") {
				dynamicLoadCss("css/AXI.css")
			}
			if (type === "Poor") {
				dynamicLoadCss("css/QTJ.css")
			}
			if (type === "Metalloid") {
				dynamicLoadCss("css/BDT.css")
			}
			if (type === "Noble") {
				dynamicLoadCss("css/XYQ.css")
			}
			if (type === "Halogen") {
				dynamicLoadCss("css/LSU.css")
			}

			$("#Top").click(function() {
				$("html , body").animate({
					scrollTop: 0
				}, "slow");
			});
		});
});
